import java.awt.Color;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.Arrays;


public class PlayerChar implements Player 
{
	double x = 100.0;
	double y = 100.0;
	int r = 0;
	int g = 0;
	int b = 0;
	boolean dir[] = new boolean[4];
	boolean inBounds;
	
	int key[];
	
	public PlayerChar(int dir2[], Color c, int spawnPosX, int spawnPosY)
	{
		key = Arrays.copyOf(dir2, dir2.length);
		
		r = c.getRed();
		g = c.getGreen();
		b = c.getBlue();
		
		x = spawnPosX;
		y = spawnPosY;
	}
	
	public static void main(String[] args) 
	{
		
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		if (x >= 0 && x < 1024 - 100 && y > 0 && y < (720 - 100))
		{
			inBounds = true;
		}
		else
		{
			inBounds = false;
		}

		if (dir[0])
		{
			y -= 5;
		}
		else if(dir[1])
		{
			y += 5;
		}
		if (dir[2])
		{
			x += 5;
		}
		else if (dir[3])
		{
			x -= 5;
		}
	}

	@Override
	public void keyPressed(KeyEvent e) 
	{
		if(e.getKeyCode() == key[0])
		{
			dir[0] = true;
		}
		if(e.getKeyCode() == key[1])
		{
			dir[1] = true;
		}
		if(e.getKeyCode() == key[2])
		{
			dir[2] = true;
		}
		if(e.getKeyCode() == key[3])
		{
			dir[3] = true;
		}
	}

	@Override
	public int getX() 
	{
		return (int)x;
	}

	@Override
	public int getY() 
	{
		return (int)y;
	}

	@Override
	public Color getColor() 
	{
		return new Color(r,g,b);
	}

	@Override
	public Shape getShape() 
	{
		return null;
	}



	@Override
	public void keyReleased(KeyEvent e) 
	{
		if(e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_W)
		{
			dir[0] = false;
		}
		if(e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_S)
		{
			dir[1] = false;
		}
		if(e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_D)
		{
			dir[2] = false;
		}
		if(e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_A)
		{
			dir[3] = false;
		}
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub

	}
}
